package ru.dcsearch.indexer;
 /***************************************************************************
 *   Modified by TMC
 *   berechitai@gmail.com
 *
 *   This file is part of DC Indexer project
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 ***************************************************************************/
/*
 *  Mobile DC - a DirectConnect client written in Java and designed for
 *  the Sony Ericsson p800/p900 or equivalent Symbian OS 7.0 platforms
 *  Copyright (C) 2004 Conrad Helgesson, vakum@home.se
 *
 *  This file is part of Mobile DC.
 *
 *  Mobile DC is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Mobile DC is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Mobile DC; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.io.InputStream;
import java.io.IOException;


public class TokenInputStream {
    private InputStream		in;
    private StringBuffer	buffer = new StringBuffer();
    private char			sep;

    public TokenInputStream(InputStream in, char sep) {
        this.in = in;
        this.sep = sep;
    }

    public String readToken() throws IOException {
        if(in.available() == 0)
        	return null;
        int ch = in.read();

        while((char)ch != sep) {
            if(ch == -1)
            	throw new IOException("End of stream!");
            buffer.append((char)ch);
            if(in.available() == 0)
            	return null;
            ch = in.read();
        }

        String result = buffer.toString();
        buffer = new StringBuffer();
        return result;
    }

    public int available() throws IOException {
        return in.available();
    }

    public int read(byte buffer[]) throws IOException {
        return in.read(buffer);
    }
}
